Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

242
Visualizações
"this" keyword in an arrow function

I understood that the "this" keyword means the current execution context, or where the code was invoked. It may be the global object or an object that called it.

const nameObj = {
  name: "Jack",
logName: function(){
console.log(this.name)}
}
nameObj.logName() // Jack

It works fine for the regular functions, but for the arrow functions it returns the global object instead:

const nameObj = {
  name: "Jack",
logName: ()=> {
// console.log(this.name) would be undefined
console.log(this)
}
}
nameObj.logName() // The window object on the browser's console

Everything is clear till this point, however, I cannot understand when it comes to nesting an arrow function inside a regular function, the "this" keyword in the arrow function refers to the object that called it instead of the usual global or window object.

const nameObj = {
  name: "Jack",
  logName: function () {
    return () => console.log(this.name);
  },
};
const arrowLogName = nameObj.logName();
arrowLogName(); // Jack

Is the arrow function implicitly "capturing" the "this" value or something else I am missing?

about 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda